package com.ruoyi.manage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.cg.pojo.Classification;
import com.ruoyi.manage.service.IClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 分类Controller
 *
 * @author ruoyi
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/classification")
public class ClassificationController extends BaseController
{
    @Autowired
    private IClassificationService classificationService;

    /**
     * 查询分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Classification classification)
    {
        startPage();
        List<Classification> list = classificationService.selectClassificationList(classification);
        return getDataTable(list);
    }

    /**
     * 导出分类列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classification classification)
    {
        List<Classification> list = classificationService.selectClassificationList(classification);
        ExcelUtil<Classification> util = new ExcelUtil<Classification>(Classification.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return success(classificationService.selectClassificationByFId(fId));
    }

    /**
     * 新增分类
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody Classification classification)
    {
        return toAjax(classificationService.insertClassification(classification));
    }

    /**
     * 修改分类
     */

    @PutMapping("edit")
    public AjaxResult edit(@RequestBody Classification classification)
    {
        return toAjax(classificationService.updateClassification(classification));
    }

    /**
     * 删除分类
     */
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(classificationService.deleteClassificationByFIds(fIds));
    }
}
